const sqlite3 = require('sqlite3').verbose();

// 连接数据库
const db = new sqlite3.Database('./db/database.db', (err) => {
    if (err) {
        console.error('Failed to connect to database:', err.message);
    } else {
        console.log('Connected to SQLite3 database.');
    }
});

// 创建用户表
db.run(`CREATE TABLE IF NOT EXISTS users (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    username TEXT UNIQUE,
    password TEXT
)`);

// 创建待办事项表
db.run(`CREATE TABLE IF NOT EXISTS todos (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    user_id INTEGER,
    content TEXT,
    status INTEGER DEFAULT 0,
    FOREIGN KEY(user_id) REFERENCES users(id)
)`);

module.exports = db;
